﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

using Twilio.TwilML.BaseTypes;

namespace Twilio.TwilML
{
    public class Record : ResponseVerb
    {
        [XmlAttribute("action"), DefaultValue(null)]
        public string Action { get; set; }

        [XmlAttribute("method"), DefaultValue(HttpMethod.Post)]
        public HttpMethod Method { get; set; }

        private int _Timeout = 5;
        [XmlAttribute("timeout"), DefaultValue(5)]
        public int Timeout {
            get
            {
                return _Timeout;
            }
            set
            {
                if (value < 0) throw new ArgumentOutOfRangeException("Timeout", "Timeout must be a positive integer.");
                else _Timeout = value;
            }
        }

        private char _FinishOnKey = '#';
        [XmlAttribute("finishOnKey"), DefaultValue('#')]
        public char FinishOnKey
        {
            get { return _FinishOnKey; }
            set
            {
                if (!char.IsDigit(value) && value != '*' || value != '#') throw new ArgumentOutOfRangeException("FinishOnKey", "FinishOnKey must be a digit, '#' or '*' character.");
                else _FinishOnKey = value;
            }
        }

        private int _MaxLength = 3600;
        [XmlAttribute("maxLength"), DefaultValue(3600)]
        public int MaxLength
        {
            get { return _MaxLength; }
            set
            {
                if (value < 1) throw new ArgumentOutOfRangeException("MaxLength", "MaxLength must be a positive integer greater than 0.");
                else _MaxLength = value;
            }
        }

        [XmlAttribute("transcribe"), DefaultValue(false)]
        public bool Transcribe { get; set; }

        [XmlAttribute("transcribeCallback"), DefaultValue(null)]
        public string TranscribeCallback { get; set; }

        [XmlAttribute("playBeep"), DefaultValue(true)]
        public bool PlayBeep { get; set; }

        public Record()
        {
            Method = HttpMethod.Post;
            PlayBeep=true;
        }
        public Record(string action) : this()
        {
            Action = action;
        }
    }
}
